<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>消息编辑页面</title>
<link rel="stylesheet" href="layui/css/layui.css" media="all">
<style>
.layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {
	height: 34px;
	line-height: 34px;
	padding: 0 8px;
}
</style>
</head>
<body>
	<form class="layui-form" action="">
		<div class="layui-form-item" style="margin-top: 20px;"
			onsubmit="false">
			<div class="layui-form-item" hidden="hidden">
				<label class="layui-form-label required"><span style="color: red;">* </span>发送人:</label>
				<div class="layui-input-block">
					<input type="text" name="mesid"  id="mesid" lay-verify="required|username" lay-reqtext="发送人获取失败" placeholder="请输入发送人" value="" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">* </span>接收人:</label>
				<div class="layui-input-inline" style="width: 350px;">
					<input type="text" name="mesreceiver" id="mesreceiver"
						lay-verify="required" lay-reqtext="接收人不能为空" placeholder="请输入接收人"
						value="" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item" hidden="hidden">
				<label class="layui-form-label"><span style="color: red;">* </span>学生id:</label>
				<div class="layui-input-inline" style="width: 350px;">
					<input type="text" name="messtuid" id="messtuid" placeholder=""
						lay-verify="required" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">* </span>学生姓名:</label>
				<div class="layui-input-inline" style="width: 350px;">
					<input type="text" name="stuname" id="stuname" placeholder="请输入学生姓名"
						lay-verify="required" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">消息内容:</label>
				<div class="layui-input-inline" style="width: 350px;">
					<textarea name="mescontent" id="mescontent" placeholder="请输入内容"
						class="layui-textarea"></textarea>

				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">消息备注:</label>
				<div class="layui-input-inline" style="width: 350px;">
					<textarea type="text" name="mesremarks" id="mesremarks"
						placeholder="请输入备注" lay-verify="required" class="layui-textarea"></textarea>
				</div>
			</div>

			<div class="layui-btn-container" style="text-align: center;">
					<button class="layui-btn" lay-submit lay-filter="messEditBtu">修改</button>
			</div>
		</div>
	</form>
	<script type="text/javascript" src="layui/layui.js"></script>
	<script src="js/Global.js" type="text/javascript" charset="utf-8"></script>
	<script>
			layui.use(['form','layedit'], function() {
				var form = layui.form,
					layer = layui.layer,
					$ = layui.$;
				var layedit = layui.layedit;
				layedit.build('content', {
				  height: 180 //设置编辑器高度
				});
				form.verify({
					username: function(value, item) { //value：表单的值、item：表单的DOM对象
							if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
								return '用户名不能有特殊字符';
							}
							if(/(^\_)|(\__)|(\_+$)/.test(value)) {
								return '用户名首尾不能出现下划线\'_\'';
							}
							if(/^\d+\d+\d$/.test(value)) {
								return '用户名不能全为数字';
							}

							//如果不想自动弹出默认提示框，可以直接返回 true，这时你可以通过其他任意方式提示（v2.5.7 新增）
							if(value === 'name' || value === 'username' || value === 'sb') {
								return '用户名不能为敏感词';
							}
						}

						//我们既支持上述函数式的方式，也支持下述数组的形式
						//数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
						,
					pass: [
						/^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'
					]
				});
				$("#userid").val(globalData.getUid());
				//监听提交
				form.on('submit(messEditBtu)', function(data) {
					data.field.mesreceiver = globalData.getUid();
					if(data.field.mesreceiver != null) {
						$.post(globalData.server + "public/update", data.field, function(data) {
							if(data.count > 0) {
								var iframeIndex = parent.layer.getFrameIndex(window.name);
								parent.layer.close(iframeIndex);
							}
						}, "json");
					} else {
						layer.msg("发送失败");
					}

					return false;
				});

			});
		</script>
</body>
</html>